/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Mr.Sam
 */
import java.awt.*;
import java.applet.*;
import java.util.*;

import fr.ove.openmath.jome.ctrlview.bidim.FormulaDisplay;
import fr.ove.openmath.jome.ctrl.linear.LinearParser;
import fr.ove.openmath.jome.model.Formula;
import TreeView.BorderContainer;
import TreeView.FormulaTreeViewer;
import fr.ove.openmath.jome.model.processor.*;
import fr.ove.openmath.jome.model.processor.Processor;
import fr.ove.openmath.jome.model.processor.ProcessorImpl;
import fr.ove.openmath.jome.model.processor.StrahlerProcessor;
import fr.ove.openmath.jome.model.processor.StrahlerProcessorInterface;
import fr.ove.openmath.jome.model.processor.DepthProcessor;
import fr.ove.openmath.jome.model.processor.DepthProcessorInterface;
import fr.ove.openmath.jome.model.processor.WidthProcessor;
import fr.ove.openmath.jome.model.processor.WidthProcessorInterface;
import fr.ove.openmath.jome.model.processor.WidthDepthProcessor;

public class AppletBigFormula extends Applet
{
    Processor p=null;
	public void init()
	{
		// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
		//symantec.itools.lang.Context.setApplet(this);
	
		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
                
		setLayout(new BorderLayout(0,0));
		setSize(750,400);
		setFont(new Font("Dialog", Font.PLAIN, 12));
		setBackground(new Color(12632256));
		parser = new fr.ove.openmath.jome.ctrl.linear.LinearParser();
		//$$ parser.move(0,0);
		formula = new fr.ove.openmath.jome.model.Formula();
		//$$ formula.move(0,0);
		panelFormula = new java.awt.Panel();
		panelFormula.setLayout(new BorderLayout(0,0));
		panelFormula.setBounds(0,0,595,232);
		panelFormula.setBackground(new Color(16777215));
		add("Center", panelFormula);
		scroll = new java.awt.ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
		scroll.setBounds(0,0,734,361);
		panelFormula.add("Center", scroll);
		display = new fr.ove.openmath.jome.ctrlview.bidim.FormulaDisplay();
		display.setLayout(null);
		display.setBounds(0,0,10,10);
		display.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		display.setForeground(new Color(0));
		display.setBackground(new Color(16777215));
		scroll.add(display);
		entry = new java.awt.TextField();
		entry.setBounds(0,208,595,24);
		panelFormula.add("South", entry);
		panelCommand = new java.awt.Panel();
		panelCommand.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
		panelCommand.setBounds(0,232,595,168);
		panelCommand.setFont(new Font("Dialog", Font.PLAIN, 12));
		add("South", panelCommand);
		innerPanelCommand = new java.awt.Panel();
		innerPanelCommand.setLayout(new BorderLayout(0,0));
		innerPanelCommand.setBounds(245,5,243,158);
		panelCommand.add(innerPanelCommand);
		borderContainer1 = new BorderContainer();
		borderContainer1.setDrawInnerBounds(false);
		borderContainer1.setDrawOuterBounds(false);
		borderContainer1.setLayout(new BorderLayout(0,0));
		borderContainer1.setBounds(0,0,100,158);
		innerPanelCommand.add("West", borderContainer1);
		labelIconification = new java.awt.Label("Iconification",Label.CENTER);
		labelIconification.setBounds(5,5,90,23);
		labelIconification.setBackground(new Color(-5329234));
		borderContainer1.add("North", labelIconification);
		borderContainer2 = new BorderContainer();
		borderContainer2.setInnerColor(new java.awt.Color(12632256));
		borderContainer2.setVerticalGap(23);
		borderContainer2.setDrawInnerBounds(false);
		borderContainer2.setDrawOuterBounds(false);
		borderContainer2.setHorizontalGap(0);
		borderContainer2.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
		borderContainer2.setBounds(5,28,90,125);
		borderContainer1.add("Center", borderContainer2);
		bcIconification = new BorderContainer();
		bcIconification.setLayout(new GridLayout(3,1,0,0));
		bcIconification.setBounds(0,23,90,79);
		borderContainer2.add(bcIconification);
		buttonIconify = new java.awt.Button();
		buttonIconify.setLabel("Iconify");
		buttonIconify.setBounds(5,5,80,23);
		buttonIconify.setBackground(new Color(12632256));
		bcIconification.add(buttonIconify);
		buttonUniconify = new java.awt.Button();
		buttonUniconify.setLabel("Uniconify");
		buttonUniconify.setBounds(5,28,80,23);
		buttonUniconify.setBackground(new Color(12632256));
		bcIconification.add(buttonUniconify);
		buttonUniconifyAll = new java.awt.Button();
		buttonUniconifyAll.setLabel("Uniconify All");
		buttonUniconifyAll.setBounds(5,51,80,23);
		buttonUniconifyAll.setBackground(new Color(12632256));
		bcIconification.add(buttonUniconifyAll);
		bcProcessing = new BorderContainer();
		bcProcessing.setInnerColor(new java.awt.Color(12632256));
		bcProcessing.setDrawInnerBounds(false);
		bcProcessing.setDrawOuterBounds(false);
		bcProcessing.setLayout(new BorderLayout(0,0));
		bcProcessing.setBounds(100,0,499,210);
		innerPanelCommand.add("Center", bcProcessing);
		labelProcessing = new java.awt.Label("Processing",Label.CENTER);
		labelProcessing.setBounds(5,5,489,23);
		labelProcessing.setBackground(new Color(-5329234));
		bcProcessing.add("North", labelProcessing);
		panelProcessing = new java.awt.Panel();
		panelProcessing.setLayout(new BorderLayout(0,0));
		panelProcessing.setBounds(5,28,489,177);
		bcProcessing.add("Center", panelProcessing);
		radioProcessing = new java.awt.Panel();
		radioProcessing.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
		radioProcessing.setBounds(0,0,489,23);
		panelProcessing.add("North", radioProcessing);
		GroupProcessing = new CheckboxGroup();
		processingOn = new java.awt.Checkbox("Enabled", GroupProcessing, false);
		processingOn.setBounds(166,0,76,23);
		radioProcessing.add(processingOn);
		processingOff = new java.awt.Checkbox("Disabled", GroupProcessing, true);
		processingOff.setBounds(242,0,80,23);
		radioProcessing.add(processingOff);
		innerPanelProcessing = new java.awt.Panel();
		innerPanelProcessing.setLayout(new BorderLayout(0,0));
		innerPanelProcessing.setBounds(0,23,489,125);
		panelProcessing.add("Center", innerPanelProcessing);
		innerPanelProcessing.setEnabled(false);
		bcStrahler = new BorderContainer();
		bcStrahler.setLayout(new BorderLayout(0,0));
		bcStrahler.setBounds(0,0,163,125);
		innerPanelProcessing.add("West", bcStrahler);
		checkboxStrahler = new java.awt.Checkbox("Strahler");
		checkboxStrahler.setBounds(5,5,153,23);
		bcStrahler.add("North", checkboxStrahler);
		panelCommandStrahler = new java.awt.Panel();
		panelCommandStrahler.setLayout(new BorderLayout(0,0));
		panelCommandStrahler.setBounds(5,28,153,92);
		bcStrahler.add("Center", panelCommandStrahler);
		panelRadioStrahler = new java.awt.Panel();
		panelRadioStrahler.setLayout(new GridLayout(2,1,0,0));
		panelRadioStrahler.setBounds(0,0,153,46);
		panelCommandStrahler.add("North", panelRadioStrahler);
		GroupStrahler = new CheckboxGroup();
		radioStrahlerSimpleIco = new java.awt.Checkbox("Simple Iconification", GroupStrahler, false);
		radioStrahlerSimpleIco.setBounds(0,0,153,23);
		panelRadioStrahler.add(radioStrahlerSimpleIco);
		radioStrahlerRecursiveIco = new java.awt.Checkbox("Recursive Iconification", GroupStrahler, true);
		radioStrahlerRecursiveIco.setBounds(0,23,153,23);
		panelRadioStrahler.add(radioStrahlerRecursiveIco);
		panelStrahlerLevel = new java.awt.Panel();
		panelStrahlerLevel.setLayout(new BorderLayout(0,0));
		panelStrahlerLevel.setBounds(0,46,153,46);
		panelCommandStrahler.add("Center", panelStrahlerLevel);
		labelStrahlerLevel = new java.awt.Label("Stralher Level : ");
		labelStrahlerLevel.setBounds(0,0,98,46);
		panelStrahlerLevel.add("West", labelStrahlerLevel);
		choiceStrahlerLevel = new java.awt.Choice();
		choiceStrahlerLevel.setBounds(98,0,55,46);
		choiceStrahlerLevel.setBackground(new Color(16777215));
		panelStrahlerLevel.add("Center", choiceStrahlerLevel);
		bcDepth = new BorderContainer();
		bcDepth.setLayout(new BorderLayout(0,0));
		bcDepth.setBounds(163,0,163,125);
		innerPanelProcessing.add("Center", bcDepth);
		checkboxDepth = new java.awt.Checkbox("Depth");
		checkboxDepth.setBounds(5,5,153,23);
		bcDepth.add("North", checkboxDepth);
		panelCommandDepth = new java.awt.Panel();
		panelCommandDepth.setLayout(new BorderLayout(0,0));
		panelCommandDepth.setBounds(5,28,153,92);
		bcDepth.add("Center", panelCommandDepth);
		panelRadioDepth = new java.awt.Panel();
		panelRadioDepth.setLayout(new GridLayout(2,1,0,0));
		panelRadioDepth.setBounds(0,0,153,46);
		panelCommandDepth.add("North", panelRadioDepth);
		GroupDepth = new CheckboxGroup();
		radioDepthSimpleIco = new java.awt.Checkbox("Simple Iconification", GroupDepth, false);
		radioDepthSimpleIco.setBounds(0,0,153,23);
		panelRadioDepth.add(radioDepthSimpleIco);
		radioDepthRecursiveIco = new java.awt.Checkbox("Recursive Iconification", GroupDepth, true);
		radioDepthRecursiveIco.setBounds(0,23,153,23);
		panelRadioDepth.add(radioDepthRecursiveIco);
		panelDepthLevel = new java.awt.Panel();
		panelDepthLevel.setLayout(new BorderLayout(0,0));
		panelDepthLevel.setBounds(0,46,153,46);
		panelCommandDepth.add("Center", panelDepthLevel);
		labelDepthLevel = new java.awt.Label("Depth Level : ");
		labelDepthLevel.setBounds(0,0,88,46);
		panelDepthLevel.add("West", labelDepthLevel);
		choiceDepthLevel = new java.awt.Choice();
		choiceDepthLevel.setBounds(88,0,65,46);
		choiceDepthLevel.setBackground(new Color(16777215));
		panelDepthLevel.add("Center", choiceDepthLevel);
		bcWidth = new BorderContainer();
		bcWidth.setLayout(new BorderLayout(0,0));
		bcWidth.setBounds(326,0,163,125);
		innerPanelProcessing.add("East", bcWidth);
		checkboxWidth = new java.awt.Checkbox("Width (Nb Children)");
		checkboxWidth.setBounds(5,5,153,23);
		bcWidth.add("North", checkboxWidth);
		panelWidthCommand = new java.awt.Panel();
		panelWidthCommand.setLayout(new BorderLayout(0,0));
		panelWidthCommand.setBounds(5,28,153,92);
		bcWidth.add("Center", panelWidthCommand);
		panelRadioWidth = new java.awt.Panel();
		panelRadioWidth.setLayout(new GridLayout(2,1,0,0));
		panelRadioWidth.setBounds(0,0,153,46);
		panelWidthCommand.add("North", panelRadioWidth);
		GroupWidth = new CheckboxGroup();
		radioWidthSimpleIco = new java.awt.Checkbox("Simple Iconification", GroupWidth, false);
		radioWidthSimpleIco.setBounds(0,0,153,23);
		panelRadioWidth.add(radioWidthSimpleIco);
		radioWidthRecursiveIco = new java.awt.Checkbox("Recursive Iconification", GroupWidth, true);
		radioWidthRecursiveIco.setBounds(0,23,153,23);
		panelRadioWidth.add(radioWidthRecursiveIco);
		panelChoiceLevel = new java.awt.Panel();
		panelChoiceLevel.setLayout(new BorderLayout(0,0));
		panelChoiceLevel.setBounds(0,46,153,23);
		panelWidthCommand.add("Center", panelChoiceLevel);
		labelWidthLevel = new java.awt.Label("Width Level : ");
		labelWidthLevel.setBounds(0,0,86,23);
		panelChoiceLevel.add("West", labelWidthLevel);
		choiceWidthLevel = new java.awt.Choice();
		choiceWidthLevel.setBounds(86,0,67,27);
		choiceWidthLevel.setBackground(new Color(16777215));
		panelChoiceLevel.add("Center", choiceWidthLevel);
		panelView = new java.awt.Panel();
		panelView.setLayout(new BorderLayout(0,0));
		panelView.setBounds(0,69,153,23);
		panelWidthCommand.add("South", panelView);
		labelView = new java.awt.Label("Elements Viewed : ");
		labelView.setBounds(0,0,119,23);
		panelView.add("West", labelView);
		textFieldView = new java.awt.TextField();
		textFieldView.setBounds(119,0,34,23);
		panelView.add("Center", textFieldView);
		bcButtonProcess = new BorderContainer();
		bcButtonProcess.setVerticalGap(3);
		bcButtonProcess.setDrawInnerBounds(false);
		bcButtonProcess.setDrawOuterBounds(false);
		bcButtonProcess.setHorizontalGap(0);
		bcButtonProcess.setLayout(new BorderLayout(0,0));
		bcButtonProcess.setBounds(0,148,489,29);
		panelProcessing.add("South", bcButtonProcess);
		buttonProcess = new java.awt.Button();
		buttonProcess.setLabel("Do Processing");
		buttonProcess.setBounds(0,3,489,23);
		buttonProcess.setBackground(new Color(12632256));
		bcButtonProcess.add("South", buttonProcess);
		buttonProcess.setEnabled(false);
		borderContainer3 = new BorderContainer();
		borderContainer3.setDrawInnerBounds(false);
		borderContainer3.setDrawOuterBounds(false);
		borderContainer3.setLayout(new BorderLayout(0,0));
		borderContainer3.setBounds(100,0,143,158);
		innerPanelCommand.add("East", borderContainer3);
		labelParameters = new java.awt.Label("Tree Parameters",Label.CENTER);
		labelParameters.setBounds(5,5,133,23);
		labelParameters.setBackground(new Color(-5329234));
		borderContainer3.add("North", labelParameters);
		borderContainer4 = new BorderContainer();
		borderContainer4.setInnerColor(new java.awt.Color(12632256));
		borderContainer4.setVerticalGap(23);
		borderContainer4.setDrawInnerBounds(false);
		borderContainer4.setDrawOuterBounds(false);
		borderContainer4.setHorizontalGap(0);
		borderContainer4.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
		borderContainer4.setBounds(5,28,133,125);
		borderContainer3.add("Center", borderContainer4);
		bcParameters = new BorderContainer();
		bcParameters.setInnerColor(new java.awt.Color(12632256));
		bcParameters.setVerticalGap(0);
		bcParameters.setHorizontalGap(0);
		bcParameters.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
		bcParameters.setBounds(5,28,123,33);
		borderContainer4.add(bcParameters);
		buttonParameters = new java.awt.Button();
		buttonParameters.setLabel("Show Parameters");
		buttonParameters.setBounds(5,5,113,23);
		buttonParameters.setBackground(new Color(12632256));
		bcParameters.add(buttonParameters);
		//}}
	
		//{{REGISTER_LISTENERS
		SymLinearParser lSymLinearParser = new SymLinearParser();
		parser.addLinearParserListener(lSymLinearParser);
		formula.addModelListener(display);
		display.addControlListener(formula);
		SymText lSymText = new SymText();
		entry.addTextListener(lSymText);
		SymAction lSymAction = new SymAction();
		entry.addActionListener(lSymAction);
		buttonIconify.addActionListener(lSymAction);
		buttonUniconify.addActionListener(lSymAction);
		buttonUniconifyAll.addActionListener(lSymAction);
		buttonProcess.addActionListener(lSymAction);
		SymItem lSymItem = new SymItem();
		processingOn.addItemListener(lSymItem);
		processingOff.addItemListener(lSymItem);
		checkboxStrahler.addItemListener(lSymItem);
		checkboxDepth.addItemListener(lSymItem);
		checkboxWidth.addItemListener(lSymItem);
		buttonParameters.addActionListener(lSymAction);
		//}}
    }
	
	//{{DECLARE_CONTROLS
	fr.ove.openmath.jome.ctrl.linear.LinearParser parser;
	fr.ove.openmath.jome.model.Formula formula;
	java.awt.Panel panelFormula;
	java.awt.ScrollPane scroll;
	fr.ove.openmath.jome.ctrlview.bidim.FormulaDisplay display;
	java.awt.TextField entry;
	java.awt.Panel panelCommand;
	java.awt.Panel innerPanelCommand;
	BorderContainer borderContainer1;
	java.awt.Label labelIconification;
	BorderContainer borderContainer2;
	BorderContainer bcIconification;
	java.awt.Button buttonIconify;
	java.awt.Button buttonUniconify;
	java.awt.Button buttonUniconifyAll;
	BorderContainer bcProcessing;
	java.awt.Label labelProcessing;
	java.awt.Panel panelProcessing;
	java.awt.Panel radioProcessing;
	java.awt.Checkbox processingOn;
	CheckboxGroup GroupProcessing;
	java.awt.Checkbox processingOff;
	java.awt.Panel innerPanelProcessing;
	BorderContainer bcStrahler;
	java.awt.Checkbox checkboxStrahler;
	java.awt.Panel panelCommandStrahler;
	java.awt.Panel panelRadioStrahler;
	java.awt.Checkbox radioStrahlerSimpleIco;
	CheckboxGroup GroupStrahler;
	java.awt.Checkbox radioStrahlerRecursiveIco;
	java.awt.Panel panelStrahlerLevel;
	java.awt.Label labelStrahlerLevel;
	java.awt.Choice choiceStrahlerLevel;
	BorderContainer bcDepth;
	java.awt.Checkbox checkboxDepth;
	java.awt.Panel panelCommandDepth;
	java.awt.Panel panelRadioDepth;
	java.awt.Checkbox radioDepthSimpleIco;
	CheckboxGroup GroupDepth;
	java.awt.Checkbox radioDepthRecursiveIco;
	java.awt.Panel panelDepthLevel;
	java.awt.Label labelDepthLevel;
	java.awt.Choice choiceDepthLevel;
	BorderContainer bcWidth;
	java.awt.Checkbox checkboxWidth;
	java.awt.Panel panelWidthCommand;
	java.awt.Panel panelRadioWidth;
	java.awt.Checkbox radioWidthSimpleIco;
	CheckboxGroup GroupWidth;
	java.awt.Checkbox radioWidthRecursiveIco;
	java.awt.Panel panelChoiceLevel;
	java.awt.Label labelWidthLevel;
	java.awt.Choice choiceWidthLevel;
	java.awt.Panel panelView;
	java.awt.Label labelView;
	java.awt.TextField textFieldView;
	BorderContainer bcButtonProcess;
	java.awt.Button buttonProcess;
	BorderContainer borderContainer3;
	java.awt.Label labelParameters;
	BorderContainer borderContainer4;
	BorderContainer bcParameters;
	java.awt.Button buttonParameters;
	//}}

	class SymLinearParser implements fr.ove.openmath.jome.ctrl.linear.events.LinearParserListener
	{
		public void consumeLinearParserEvent(fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent event)
		{
			Object object = event.getSource();
			if (object == parser)
				parser_consumeLinearParserEvent(event);
		}
	}

	void parser_consumeLinearParserEvent(fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// consumeLinearParserEvent...
		{
			formula.consumeLinearParserEvent(event);
		}
		//}}
	}

	class SymText implements java.awt.event.TextListener
	{
		public void textValueChanged(java.awt.event.TextEvent event)
		{
			Object object = event.getSource();
			if (object == entry)
				entry_TextValueChanged(event);
		}
	}

	void entry_TextValueChanged(java.awt.event.TextEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// parse... Get the contents of the TextField
		{
			parser.parse(entry.getText());
		}
		//}}
			 
		//{{CONNECTION
		// Validate the ScrollPane
		scroll.validate();
		//}}
		
		
	    if (processingOn.getState()) {
            if (checkboxStrahler.getState()) {
                // On met à jour la liste des valeurs de Strahler
	            populateListStrahler();
            }
            
            if (checkboxDepth.getState()) {
                // On met à jour la liste des profondeur
	            populateListDepth();
            }
            
            if (checkboxWidth.getState()) {
                // On met à jour la liste des widths
	            populateListWidth();
	            // On met à jour la valeur du nombre de fils vus
	            textFieldView.setText(""+p.getLevel());
            }
        }		
	}

	class SymAction implements java.awt.event.ActionListener
	{
		public void actionPerformed(java.awt.event.ActionEvent event)
		{
			Object object = event.getSource();
			if (object == entry)
				entry_EnterHit(event);
			else if (object == buttonIconify)
				buttonIconify_ActionPerformed(event);
			else if (object == buttonUniconify)
				buttonUniconify_ActionPerformed(event);
			else if (object == buttonUniconifyAll)
				buttonUniconifyAll_ActionPerformed(event);
			else if (object == buttonProcess)
				buttonProcess_ActionPerformed(event);
			else if (object == buttonParameters)
				buttonParameters_ActionPerformed(event);
		}
	}

	void entry_EnterHit(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// parse... Get the contents of the TextField
		{
			parser.parse(entry.getText());
		}
		//}}
			 
		//{{CONNECTION
		// Validate the ScrollPane
		scroll.validate();
		//}}
		
		
	    if (processingOn.getState()) {
            if (checkboxStrahler.getState()) {
                // On met à jour la liste des valeurs de Strahler
	            populateListStrahler();
            }
            
            if (checkboxDepth.getState()) {
                // On met à jour la liste des profondeurs
	            populateListDepth();
            }
            
            if (checkboxWidth.getState()) {
                // On met à jour la liste des widths
	            populateListWidth();
	            // On met à jour la valeur du nombre de fils vus
	            textFieldView.setText(""+((WidthProcessor) p).getView());
            }
        }		
	}

	void buttonIconify_ActionPerformed(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// iconify
		{
			display.iconify();
		}
		//}}
	}

	void buttonUniconify_ActionPerformed(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// uniconify
		{
			display.uniconify();
		}
		//}}
	}

	void buttonUniconifyAll_ActionPerformed(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// uniconifyAll
		{
			display.uniconifyAll();
		}
		//}}
	}

	void buttonProcess_ActionPerformed(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// doProcess.
		{
		    if (p != null) {
    		    // Initialisation du processeur
    		    initProcessor();
    		    // Traitement de la formule.
    		    p.setUpdateDisplay(true);
    			formula.doProcess();
    		    p.setUpdateDisplay(false);
    		    
    		    // validate du scrollpane
    		    scroll.validate();
    		}
		}
		//}}
	}

	class SymItem implements java.awt.event.ItemListener
	{
		public void itemStateChanged(java.awt.event.ItemEvent event)
		{
			Object object = event.getSource();
			if (object == processingOn)
				processingOn_ItemStateChanged(event);
			else if (object == processingOff)
				processingOff_ItemStateChanged(event);
			else if (object == checkboxStrahler)
				checkboxStrahler_ItemStateChanged(event);
			else if (object == checkboxDepth)
				checkboxDepth_ItemStateChanged(event);
			else if (object == checkboxWidth)
				checkboxWidth_ItemStateChanged(event);
		}
	}

	void processingOn_ItemStateChanged(java.awt.event.ItemEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// Enable the Button on condition... Is Checkbox On?
		buttonProcess.setEnabled(processingOn.getState());
		//}}
			 
		//{{CONNECTION
		// Enable the Panel on condition... Is Checkbox On?
		innerPanelProcessing.setEnabled(processingOn.getState());
		//}}
		
		formula.setDoProcessing(true);
        formula.setProcessor(getProcessor());
	}

	void processingOff_ItemStateChanged(java.awt.event.ItemEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// Disable the Button on condition... Is Checkbox On?
		buttonProcess.setEnabled(! processingOff.getState());
		//}}
			 
		//{{CONNECTION
		// Disable the Panel on condition... Is Checkbox On?
		innerPanelProcessing.setEnabled(! processingOff.getState());
		//}}
		
		formula.setDoProcessing(false);
        formula.setProcessor(null);
	}
	
	
	public Processor getProcessor() {
		// On détermine le processor à mettre à la formule.
        if (checkboxStrahler.getState()) {
            if (checkboxDepth.getState()) {
                if (checkboxWidth.getState()) {
                    // Processeur Strahler + Depth + Width
                    System.out.println("Processeur Strahler + Depth + Width");
                }
                else
                    // Processeur Strahler + Depth
                    System.out.println("Processeur Strahler + Depth");
            }
            else if (checkboxWidth.getState()) {
                // Processeur Strahler + Width
                System.out.println("Processeur Strahler + Width");
            }
            else {
                // Processeur Strahler
                System.out.println("Processeur Strahler");
        		p = new fr.ove.openmath.jome.model.processor.StrahlerProcessor(formula);
        	}
        }
        else if (checkboxDepth.getState()) {
            if (checkboxWidth.getState()) {
                // Processeur Depth + Width
                System.out.println("Processeur Width + Depth");
                p = new fr.ove.openmath.jome.model.processor.WidthDepthProcessor(formula);
            }
            else {
                // Processeur Depth
                System.out.println("Processeur Depth");
        		p = new fr.ove.openmath.jome.model.processor.DepthProcessor(formula);
        	}
        }
        else if (checkboxWidth.getState()) {
            // Processeur Width
            System.out.println("Processeur Width");
            p = new fr.ove.openmath.jome.model.processor.WidthProcessor(formula);
        }
        else {
            // Pas de processeur.
            System.out.println("Pas de processeur");
            p = null;
        }
        return p;
	}
	
	public void initProcessor() {
	    int level;
	    // Initialisation du processeur Strahler
        if (checkboxStrahler.getState()) {
            try {
                ((StrahlerProcessorInterface) p).setStrahlerLevel(Integer.parseInt(choiceStrahlerLevel.getSelectedItem()));
            }
            catch (NumberFormatException nfe) {
                System.out.println("Invalid Strahler Value Specified");
                ((StrahlerProcessorInterface) p).setStrahlerLevel(1); // On n'iconifie rien.
            }
            
            if (radioStrahlerSimpleIco.getState())
                p.setProcessingId(ProcessorImpl.SIMPLE_ICONIFICATION);
            else
                p.setProcessingId(ProcessorImpl.RECURSIVE_ICONIFICATION);
        }
        
        // Initialisation du processur Depth
        if (checkboxDepth.getState()) {
            try {
                ((DepthProcessorInterface) p).setDepthLevel(Integer.parseInt(choiceDepthLevel.getSelectedItem()));
            }
            catch (NumberFormatException nfe) {
                System.out.println("Invalid Depth Value Specified");
                ((DepthProcessorInterface) p).setDepthLevel(1); // On n'iconifie rien.
            }
            
            if (radioDepthSimpleIco.getState())
                p.setProcessingId(ProcessorImpl.SIMPLE_ICONIFICATION);
            else
                p.setProcessingId(ProcessorImpl.RECURSIVE_ICONIFICATION);
        }
        
        // Initialisation du processuer Width
        if (checkboxWidth.getState()) {
            try {
                ((WidthProcessorInterface) p).setWidthLevel(Integer.parseInt(choiceWidthLevel.getSelectedItem()));
                try {
                    ((WidthProcessorInterface) p).setView(Integer.parseInt(textFieldView.getText()));
                }
                catch (NumberFormatException nfe) {
                    System.out.println("Invalid View Value Specified");
                    ((WidthProcessorInterface) p).setView(p.getLevel()/2);
                }
            }
            catch (NumberFormatException nfe) {
                System.out.println("Invalid Width Value Specified");
                ((WidthProcessorInterface) p).setWidthLevel(1); // On n'iconifie rien.
            }
            
            if (radioWidthSimpleIco.getState())
                p.setProcessingId(ProcessorImpl.SIMPLE_ICONIFICATION);
            else
                p.setProcessingId(ProcessorImpl.RECURSIVE_ICONIFICATION);
        }
	}

	private void populateListStrahler() {
	    Vector list = ((StrahlerProcessorInterface) p).getStrahlerList();
	    choiceStrahlerLevel.removeAll();
	    Integer value;
	    for (Enumeration e = list.elements(); e.hasMoreElements(); ) 
	        choiceStrahlerLevel.addItem("" + ((Integer) e.nextElement()).intValue());
	    choiceStrahlerLevel.select("" + p.getLevel());
	}
	
	private void populateListDepth() {
	    int depthMax = ((DepthProcessorInterface) p).getMaxDepthValue();
	    choiceDepthLevel.removeAll();
	    for (int i = depthMax; i > 0; i--)
	        choiceDepthLevel.addItem("" + i);
	    choiceDepthLevel.select("" + p.getLevel());
	}
	
	private void populateListWidth() {
	    Vector list = ((WidthProcessorInterface) p).getWidthList();
	    choiceWidthLevel.removeAll();
	    Integer value;
	    for (Enumeration e = list.elements(); e.hasMoreElements(); ) 
	        choiceWidthLevel.addItem("" + ((Integer) e.nextElement()).intValue());
	    choiceWidthLevel.select("" + p.getLevel());
	}
	
	void checkboxStrahler_ItemStateChanged(java.awt.event.ItemEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// setProcessor
		{
		    // On affecte le processeur
			formula.setProcessor(getProcessor());
		}
		//}}
	}

	void checkboxDepth_ItemStateChanged(java.awt.event.ItemEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// setProcessor
		{
		    // On affecte le processeur
			formula.setProcessor(getProcessor());
		}
		//}}
	}

	void checkboxWidth_ItemStateChanged(java.awt.event.ItemEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// setProcessor
		{
		    // On affecte le processeur
			formula.setProcessor(getProcessor());
		}
		//}}
	}

	void buttonParameters_ActionPerformed(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// 
		{
			new FormulaTreeViewer(formula);
		}
		//}}
	}
}
